package mark.tom.pistols.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project

class PistolsPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        project.task('syncDebugAssets', type: SyncDebugAssetsTask)
        project.task('syncReleaseAssets', type: SyncReleaseAssetsTask)

        project.extensions.create('pistols', PistolsExtension)

        project.afterEvaluate {
            project.tasks.matching {
                it.name.startsWith('merge') && it.name.endsWith('DebugAssets')
            }.each { task ->
                project.tasks.getByName("syncDebugAssets").dependsOn.add(task)
            }
            project.tasks.matching {
                it.name.startsWith('package') && it.name.endsWith('Debug')
            }.each { task ->
                task.dependsOn.add(project.tasks.getByName("syncDebugAssets"))
            }

            project.tasks.matching {
                it.name.startsWith('merge') && it.name.endsWith('ReleaseAssets')
            }.each { task ->
                project.tasks.getByName("syncReleaseAssets").dependsOn.add(task)
            }
            project.tasks.matching {
                it.name.startsWith('package') && it.name.endsWith('Release')
            }.each { task ->
                task.dependsOn.add(project.tasks.getByName("syncReleaseAssets"))
            }
        }
    }
}
